<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>泡泡玛特 - 潮流玩具购物平台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }

        :root {
            --primary: #8a2be2;
            --secondary: #ff6ec7;
            --accent: #00c8ff;
            --light: #f9f5ff;
            --dark: #2a0a4a;
        }

        body {
            background-color: #f8f7fc;
            color: #333;
            overflow-x: hidden;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 0 20px;
        }

        /* 头部导航 */
        header {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            box-shadow: 0 4px 12px rgba(138, 43, 226, 0.2);
            position: sticky;
            top: 0;
            z-index: 1000;
        }

        .header-top {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 0;
        }

        .logo {
            display: flex;
            align-items: center;
            color: white;
            text-decoration: none;
            font-size: 28px;
            font-weight: 800;
        }

        .logo i {
            margin-right: 10px;
            font-size: 32px;
        }

        .search-bar {
            flex: 1;
            max-width: 600px;
            margin: 0 30px;
            position: relative;
        }

        .search-bar input {
            width: 100%;
            padding: 12px 20px;
            border-radius: 30px;
            border: none;
            font-size: 16px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
        }

        .search-bar button {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            background: var(--accent);
            border: none;
            color: white;
            width: 36px;
            height: 36px;
            border-radius: 50%;
            cursor: pointer;
        }

        .nav-icons {
            display: flex;
            gap: 20px;
        }

        .nav-icon {
            color: white;
            font-size: 22px;
            position: relative;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .nav-icon-text {
            font-size: 16px;
            font-weight: 500;
        }

        .cart-count {
            position: absolute;
            top: -8px;
            right: -8px;
            background: var(--accent);
            color: white;
            font-size: 12px;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
        }

        /* 主菜单 */
        .main-nav {
            background: rgba(255, 255, 255, 0.15);
            backdrop-filter: blur(10px);
        }

        .main-nav ul {
            display: flex;
            list-style: none;
            padding: 12px 0;
        }

        .main-nav li {
            margin-right: 30px;
        }

        .main-nav a {
            color: white;
            text-decoration: none;
            font-weight: 600;
            font-size: 16px;
            padding: 8px 0;
            position: relative;
        }

        .main-nav a:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 0;
            height: 2px;
            background: var(--accent);
            transition: width 0.3s;
        }

        .main-nav a:hover:after {
            width: 100%;
        }

        /* 轮播图 */
        .hero-slider {
            height: 500px;
            margin: 20px 0 40px;
            position: relative;
            overflow: hidden;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(138, 43, 226, 0.15);
        }

        .slide {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-size: cover;
            background-position: center;
            opacity: 0;
            transition: opacity 1s ease;
            display: flex;
            align-items: center;
            padding: 0 80px;
        }

        .slide.active {
            opacity: 1;
            z-index: 1;
        }

        .slide-content {
            max-width: 500px;
            color: white;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
            animation: slideIn 0.8s ease;
        }

        @keyframes slideIn {
            from {
                transform: translateX(-50px);
                opacity: 0;
            }
            to {
                transform: translateX(0);
                opacity: 1;
            }
        }

        .slide-content h2 {
            font-size: 42px;
            margin-bottom: 15px;
            line-height: 1.2;
        }

        .slide-content p {
            font-size: 18px;
            margin-bottom: 25px;
        }

        .btn {
            display: inline-block;
            padding: 12px 32px;
            background: var(--accent);
            color: white;
            text-decoration: none;
            font-weight: 600;
            border-radius: 30px;
            transition: all 0.3s;
            box-shadow: 0 4px 15px rgba(0, 200, 255, 0.4);
        }

        .btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(0, 200, 255, 0.6);
        }

        .slider-nav {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            gap: 10px;
            z-index: 10;
        }

        .slider-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.5);
            cursor: pointer;
        }

        .slider-dot.active {
            background: var(--accent);
        }

        /* 商品展示区域 */
        .products-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 25px;
            margin-bottom: 40px;
        }

        .product-card {
            background: white;
            border-radius: 16px;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            transition: all 0.3s;
            cursor: pointer;
        }

        .product-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 15px 30px rgba(138, 43, 226, 0.2);
        }

        .product-info {
            padding: 20px;
        }

        .product-info h3 {
            font-size: 18px;
            margin-bottom: 8px;
            color: var(--dark);
        }

        .product-info p {
            color: #777;
            font-size: 14px;
            margin-bottom: 15px;
            line-height: 1.5;
        }

        .product-price {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .price {
            font-size: 20px;
            font-weight: 700;
            color: var(--primary);
        }

        .add-to-cart {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--primary);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.3s;
        }

        .add-to-cart:hover {
            background: var(--secondary);
            transform: rotate(15deg);
        }

        /* 用户状态 */
        .user-status {
            position: fixed;
            top: 100px;
            right: 20px;
            background: white;
            border-radius: 12px;
            padding: 15px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            z-index: 1000;
            display: none;
            min-width: 200px;
        }

        .user-status.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .user-header {
            display: flex;
            align-items: center;
            gap: 10px;
            padding-bottom: 10px;
            margin-bottom: 10px;
            border-bottom: 1px solid #eee;
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 18px;
        }

        .user-name {
            font-weight: 600;
            font-size: 16px;
        }

        .user-menu {
            list-style: none;
        }

        .user-menu li {
            margin-bottom: 8px;
        }

        .user-menu a {
            display: block;
            padding: 8px 10px;
            border-radius: 6px;
            color: #555;
            text-decoration: none;
            transition: all 0.2s;
            display: flex;
            align-items: center;
        }

        .user-menu a:hover {
            background: #f5f2ff;
            color: var(--primary);
        }

        .user-menu a i {
            margin-right: 8px;
            width: 20px;
            text-align: center;
        }

        /* 页脚 */
        footer {
            background: var(--dark);
            color: white;
            padding: 60px 0 30px;
            margin-top: 60px;
        }

        .footer-content {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 30px;
        }

        .footer-column h3 {
            font-size: 20px;
            margin-bottom: 20px;
            position: relative;
            padding-bottom: 10px;
        }

        .footer-column h3:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 40px;
            height: 3px;
            background: var(--accent);
        }

        .footer-column ul {
            list-style: none;
        }

        .footer-column ul li {
            margin-bottom: 12px;
        }

        .footer-column a {
            color: #ccc;
            text-decoration: none;
            transition: all 0.3s;
        }

        .footer-column a:hover {
            color: var(--accent);
            padding-left: 5px;
        }

        .social-links {
            display: flex;
            gap: 15px;
            margin-top: 20px;
        }

        .social-links a {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            color: white;
            font-size: 18px;
            transition: all 0.3s;
        }

        .social-links a:hover {
            background: var(--accent);
            transform: translateY(-5px);
        }

        .copyright {
            text-align: center;
            padding-top: 30px;
            margin-top: 30px;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            color: #aaa;
            font-size: 14px;
        }

        /* 响应式设计 */
        @media (max-width: 1100px) {
            .products-grid {
                grid-template-columns: repeat(3, 1fr);
            }
        }

        @media (max-width: 900px) {
            .footer-content {
                grid-template-columns: repeat(2, 1fr);
            }

            .slide {
                padding: 0 40px;
            }

            .slide-content h2 {
                font-size: 32px;
            }
        }

        @media (max-width: 768px) {
            .header-top {
                flex-direction: column;
                gap: 15px;
            }

            .search-bar {
                margin: 10px 0;
                max-width: 100%;
            }

            .main-nav ul {
                overflow-x: auto;
                padding-bottom: 5px;
            }

            .products-grid {
                grid-template-columns: repeat(2, 1fr);
            }

            .nav-icon-text {
                display: none;
            }
        }

        @media (max-width: 480px) {
            .products-grid {
                grid-template-columns: 1fr;
            }

            .footer-content {
                grid-template-columns: 1fr;
            }

            .slide-content h2 {
                font-size: 24px;
            }

            .slide-content p {
                font-size: 16px;
            }
        }

        /* 在样式部分添加 */
        .user-details {
            padding: 15px;
            background: #f9f5ff;
            border-radius: 8px;
            margin: 10px;
        }

        .user-details div {
            display: flex;
            align-items: center;
            margin-bottom: 8px;
            font-size: 14px;
        }

        .user-details i {
            width: 20px;
            text-align: center;
            margin-right: 10px;
            color: var(--primary);
        }

        .user-email {
            font-size: 13px;
            color: #777;
            margin-top: 4px;
        }
    </style>
</head>
<body>
<!-- 顶部导航 -->
<header>
    <div class="container">
        <div class="header-top">
            <a href="index.html" class="logo">
                <i class="fas fa-gem"></i>
                POP MART
            </a>

            <div class="search-bar">
                <input type="text" placeholder="搜索潮玩、艺术家系列...">
                <button><i class="fas fa-search"></i></button>
            </div>

            <div class="nav-icons">
                <!-- 登录状态显示 -->
                <div class="nav-icon" id="userIcon">
                    <i class="fas fa-user"></i>
                    <span class="nav-icon-text" id="loginText">登录</span>
                </div>
                <div class="nav-icon">
                    <i class="fas fa-heart"></i>
                    <span class="nav-icon-text">收藏</span>
                </div>
                <div class="nav-icon">
                    <i class="fas fa-shopping-cart"></i>
                    <span class="cart-count" id="cartCount">0</span>
                    <span class="nav-icon-text">购物车</span>
                    <a href="cart.html?userId=1"
                       style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></a>
                </div>
            </div>
        </div>

        <nav class="main-nav">
            <ul>
                <li><a href="#">首页</a></li>
                <li><a href="#">热门分类</a></li>
                <li><a href="#">新品上市</a></li>
                <li><a href="#">热门系列</a></li>
                <li><a href="#">盲盒专区</a></li>
                <li><a href="#">艺术家</a></li>
                <li><a href="#">限定商品</a></li>
                <li><a href="#">促销活动</a></li>
                <li><a href="order.html">我的订单</a></li>  <!-- 新增链接 -->
                <li><a href="#">会员中心</a></li>
            </ul>
        </nav>
    </div>
</header>

<!-- 修改后的用户状态面板 -->
<div class="user-status" id="userStatus">
    <div class="user-header">
        <div class="user-avatar" id="userAvatar">U</div>
        <div class="user-name" id="userName">未登录用户</div>
    </div>

    <!-- 添加用户详细信息区域 -->
    <div class="user-details">
        <div class="detail-item">
            <i class="fas fa-envelope"></i>
            <span id="userEmail">未设置</span>
        </div>
        <div class="detail-item">
            <i class="fas fa-phone"></i>
            <span id="userPhone">未设置</span>
        </div>
        <div class="detail-item">
            <i class="fas fa-venus-mars"></i>
            <span id="userGender">未设置</span>
        </div>
        <div class="detail-item">
            <i class="fas fa-birthday-cake"></i>
            <span id="userBirthday">未设置</span>
        </div>
    </div>

    <ul class="user-menu">
        <li><a href="#"><i class="fas fa-user"></i> 个人中心</a></li>
        <li><a href="#"><i class="fas fa-box"></i> 我的订单</a></li>
        <li><a href="#"><i class="fas fa-heart"></i> 我的收藏</a></li>
        <li><a href="#" id="logoutBtn"><i class="fas fa-sign-out-alt"></i> 退出登录</a></li>
    </ul>
</div>

<!-- 轮播图 -->
<div class="container">
    <div class="hero-slider">
        <div class="slide active"
             style="background: linear-gradient(90deg, rgba(138,43,226,0.8), rgba(138,43,226,0.4)), url('https://images.unsplash.com/photo-1606310737840-eba660f37a26?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80')">
            <div class="slide-content">
                <h2>全新系列 Molly 奇幻梦境</h2>
                <p>开启你的奇幻收藏之旅，12款独特设计等你发现，隐藏款概率提升！</p>
                <a href="#" class="btn">立即探索</a>
            </div>
        </div>
        <div class="slide"
             style="background: linear-gradient(90deg, rgba(255,110,199,0.8), rgba(255,110,199,0.4)), url('https://images.unsplash.com/photo-1587654780291-39c9404d746b?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80')">
            <div class="slide-content">
                <h2>Dimoo 太空旅行系列</h2>
                <p>与Dimoo一起探索未知宇宙，限量版宇航员Dimoo等你带回家！</p>
                <a href="#" class="btn">立即购买</a>
            </div>
        </div>
        <div class="slide"
             style="background: linear-gradient(90deg, rgba(0,200,255,0.8), rgba(0,200,255,0.4)), url('https://images.unsplash.com/photo-1583394838336-acd977736f90?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1456&q=80')">
            <div class="slide-content">
                <h2>夏日限定优惠</h2>
                <p>全场潮玩低至7折，满299元包邮，VIP会员额外享95折！</p>
                <a href="#" class="btn">查看优惠</a>
            </div>
        </div>

        <div class="slider-nav">
            <div class="slider-dot active"></div>
            <div class="slider-dot"></div>
            <div class="slider-dot"></div>
        </div>
    </div>
</div>

<!-- 商品展示区域 -->
<div class="container">
    <div class="products-grid" id="productsGrid"></div>
</div>

<!-- 页脚 -->
<footer>
    <div class="container">
        <div class="footer-content">
            <div class="footer-column">
                <h3>关于我们</h3>
                <ul>
                    <li><a href="#">品牌故事</a></li>
                    <li><a href="#">企业文化</a></li>
                    <li><a href="#">联系我们</a></li>
                    <li><a href="#">加入我们</a></li>
                    <li><a href="#">门店查询</a></li>
                </ul>
            </div>

            <div class="footer-column">
                <h3>客户服务</h3>
                <ul>
                    <li><a href="#">常见问题</a></li>
                    <li><a href="#">配送说明</a></li>
                    <li><a href="#">退换政策</a></li>
                    <li><a href="#">会员制度</a></li>
                    <li><a href="#">防伪查询</a></li>
                </ul>
            </div>

            <div class="footer-column">
                <h3>商务合作</h3>
                <ul>
                    <li><a href="#">IP合作</a></li>
                    <li><a href="#">渠道合作</a></li>
                    <li><a href="#">媒体合作</a></li>
                    <li><a href="#">企业采购</a></li>
                    <li><a href="#">展会活动</a></li>
                </ul>
            </div>

            <div class="footer-column">
                <h3>关注我们</h3>
                <p>获取最新潮玩资讯和独家优惠</p>
                <div class="social-links">
                    <a href="#"><i class="fab fa-weibo"></i></a>
                    <a href="#"><i class="fab fa-weixin"></i></a>
                    <a href="#"><i class="fab fa-qq"></i></a>
                    <a href="#"><i class="fab fa-douban"></i></a>
                    <a href="#"><i class="fab fa-tiktok"></i></a>
                </div>
            </div>
        </div>

        <div class="copyright">
            <p>© 2023 POP MART 泡泡玛特 版权所有 | 潮流玩具购物平台</p>
            <p>京ICP备12345678号 | 客服电话：400-123-4567</p>
        </div>
    </div>
</footer>

<script>

    // 轮播图功能
    document.addEventListener('DOMContentLoaded', function () {
        // 轮播图功能
        const slides = document.querySelectorAll('.slide');
        const dots = document.querySelectorAll('.slider-dot');
        let currentSlide = 0;

        function showSlide(n) {
            slides.forEach(slide => slide.classList.remove('active'));
            dots.forEach(dot => dot.classList.remove('active'));

            currentSlide = (n + slides.length) % slides.length;

            slides[currentSlide].classList.add('active');
            dots[currentSlide].classList.add('active');
        }

        // 添加点按事件
        dots.forEach((dot, index) => {
            dot.addEventListener('click', () => {
                showSlide(index);
            });
        });

        // 自动轮播
        setInterval(() => {
            showSlide(currentSlide + 1);
        }, 5000);

        // 用户状态功能
        const userIcon = document.getElementById('userIcon');
        const userStatus = document.getElementById('userStatus');
        const loginText = document.getElementById('loginText');
        const userName = document.getElementById('userName');
        const userAvatar = document.getElementById('userAvatar');
        const logoutBtn = document.getElementById('logoutBtn');

        // 检查本地存储中的登录状态
        const savedUser = localStorage.getItem('popmartUser');

        console.log("检查本地存储中的登录状态:", savedUser);
        let isLoggedIn = false;
        let userId;

        if (savedUser) {
            const user = JSON.parse(savedUser);
            updateUserStatus(user);
            isLoggedIn = true;
            userId = user.uId; // 获取用户 ID
        }

        // 获取用户详细信息函数
        async function fetchUserDetails(userId) {
            try {
                const response = await fetch(`/user/${userId}`);
                if (!response.ok) {
                    throw new Error('获取用户信息失败');
                }
                return await response.json();
            } catch (error) {
                console.error('获取用户信息失败:', error);
                return null;
            }
        }

        // 更新用户状态函数
        function updateUserStatus(user) {
            console.log("更新用户状态:", user);

            // 确保这些元素存在
            const loginText = document.getElementById('loginText');
            const userName = document.getElementById('userName');
            const userAvatar = document.getElementById('userAvatar');

            if (loginText) loginText.textContent = user.uName || '未登录';
            if (userName) userName.textContent = user.uName || '未登录用户';
            if (userAvatar) {
                userAvatar.textContent = (user.uName && user.uName.charAt(0)) || 'U';
                userAvatar.style.background = 'linear-gradient(135deg, #ff6ec7, #00c8ff)';
            }

            // 确保这些元素存在
            const userEmail = document.getElementById('userEmail');
            const userPhone = document.getElementById('userPhone');
            const userGender = document.getElementById('userGender');
            const userBirthday = document.getElementById('userBirthday');

            // 显示用户详细信息
            if (userEmail) userEmail.textContent = user.uEmail || '未设置';
            if (userPhone) userPhone.textContent = user.uPhone || '未设置';
            if (userGender) userGender.textContent = user.uSex || '未设置';

            // 处理生日
            if (userBirthday) {
                userBirthday.textContent = user.uBirthday || '未设置';
            }

            isLoggedIn = true;
            // 保存用户信息到 localStorage
            localStorage.setItem('popmartUser', JSON.stringify(user));
        }


        // 用户图标点击事件
        userIcon.addEventListener('click', function (e) {
            console.log("用户图标被点击");

            if (!isLoggedIn) {
                window.location.href = 'login.html';
            } else {
                const savedUserJson = localStorage.getItem('popmartUser');
                console.log("本地存储的用户信息:", savedUserJson);

                if (savedUserJson) {
                    try {
                        const savedUser = JSON.parse(savedUserJson);
                        console.log("解析后的用户对象:", savedUser);
                        updateUserStatus(savedUser);
                    } catch (error) {
                        console.error("解析用户信息失败:", error);
                    }
                }

                // 切换用户状态面板显示
                userStatus.classList.toggle('active');
            }
        });

        // 登出功能
        logoutBtn.addEventListener('click', function (e) {
            e.preventDefault();
            localStorage.removeItem('popmartUser');
            isLoggedIn = false;
            userStatus.classList.remove('active');
            loginText.textContent = '登录';
            userName.textContent = '未登录用户';
            userAvatar.textContent = 'U';
            userAvatar.style.background = 'linear-gradient(135deg, var(--primary), var(--secondary))';

            // 显示登出成功消息
            showMessage('您已成功退出登录');
        });

        // 显示消息
        function showMessage(text) {
            alert(text);
        }

        // 点击页面其他区域关闭用户菜单
        document.addEventListener('click', function (e) {
            if (!userIcon.contains(e.target) && !userStatus.contains(e.target)) {
                userStatus.classList.remove('active');
            }
        });

        // 获取商品信息并展示
        async function fetchGoods() {
            try {
                const response = await fetch('/goods/all');
                if (!response.ok) {
                    throw new Error('获取商品信息失败');
                }
                const goods = await response.json();
                const productsGrid = document.getElementById('productsGrid');

                // 清空现有内容（如果有）
                productsGrid.innerHTML = '';

                goods.forEach(good => {
                    const productCard = document.createElement('div');
                    productCard.classList.add('product-card');
                    productCard.addEventListener('click', () => {
                        window.location.href = `product-detail.html?id=${good.gId}`;
                    });

                    // 创建商品图片容器
                    const productImage = document.createElement('div');
                    productImage.classList.add('product-image');

                    // 添加商品图片（如果有图片URL）
                    if (good.gImage) {
                        const img = document.createElement('img');
                        img.src = good.gImage;
                        img.alt = good.gName;
                        productImage.appendChild(img);
                    } else {
                        // 占位符
                        const placeholder = document.createElement('div');
                        placeholder.classList.add('image-placeholder');
                        placeholder.textContent = 'No Image';
                        productImage.appendChild(placeholder);
                    }

                    const productInfo = document.createElement('div');
                    productInfo.classList.add('product-info');

                    const productName = document.createElement('h3');
                    productName.textContent = good.gName;

                    const productDes = document.createElement('p');
                    productDes.textContent = good.gDes;

                    const productPrice = document.createElement('div');
                    productPrice.classList.add('product-price');

                    const price = document.createElement('span');
                    price.classList.add('price');
                    price.textContent = `¥${good.gPrice}`;

                    const addToCart = document.createElement('div');
                    addToCart.classList.add('add-to-cart');
                    addToCart.innerHTML = '<i class="fas fa-plus"></i>';

                    productPrice.appendChild(price);
                    productPrice.appendChild(addToCart);

                    productInfo.appendChild(productName);
                    productInfo.appendChild(productDes);
                    productInfo.appendChild(productPrice);

                    productCard.appendChild(productImage);
                    productCard.appendChild(productInfo);
                    productsGrid.appendChild(productCard);
                });
            } catch (error) {
                console.error('获取商品信息失败:', error);
                // 显示错误信息
                productsGrid.innerHTML = '<p class="error">加载商品失败，请稍后重试</p>';
            }
        }

        fetchGoods();
    });
</script>
</body>
</html>